using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AssetFrame.Message;
using System.Reflection;
using SysFrame.Message;
using SysFrame.BP;
using System.Data;

namespace AssetFrame.BP
{
    /// <summary>
    /// sys_asset_a1方法
    /// </summary>
    public class BLLsys_asset_a1
    {
        public Isys_asset_a1 interface_sys_asset_a1;

        public BLLsys_asset_a1()
        {
            object obj = BPBase.GetAchieve("AssetFrame.BP", "sys_asset_a1");
            interface_sys_asset_a1 = (Isys_asset_a1)obj;
        }


        /// <summary>
        /// 得到sys_asset_a1实体
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public List<Mssys_asset_a1> Getsys_asset_a1MsByQuery(MsQuery msq)
        {
            if (msq.typecode1 == "")
            {
                msq.typecode1 = "sys";
            }
            Mssystem_1 mssys1 = (Mssystem_1)msq.obj1;//当前用户
            //分类码资产需要加入角色条件
            if (mssys1!=null && !mssys1.isadmin && msq.typecode1 == "asset")
            {
                try
                {
                    BLLsys_asset_a2 sysa2 = new BLLsys_asset_a2();
                    MsQuery msqsysa2 = new MsQuery();
                    msqsysa2.strquery = " and SYS_ASSET_A2_10='" + mssys1.sys10.System_10_10 + "'";
                    List<Mssys_asset_a2> listsysa2 = sysa2.Getsys_asset_a2MsByQuery(msqsysa2);
                    List<int> listid = listsysa2.ConvertAll(m => m.SYS_ASSET_A2_20);
                    listid.Add(-1);
                    msq.strquery += " and AUTOID in ('" + string.Join("','", listid) + "')";
                }
                catch { }
            }
            else if (msq.typecode1 == "sys")
            {

            }
            return interface_sys_asset_a1.Getsys_asset_a1MsByQuery(msq);
        }

        /// <summary>
        /// 通过AUTOID得到实体
        /// </summary>
        /// <param name="AUTOID">ID</param>
        /// <returns>实体</returns>
        public Mssys_asset_a1 Getsys_asset_a1MsByKey(string AUTOID)
        {
            MsQuery msquery = new MsQuery();
            msquery.strquery += " and AUTOID='" + AUTOID + "' ";
            List<Mssys_asset_a1> lstData = Getsys_asset_a1MsByQuery(msquery);
            return lstData[0];
        }

        /// <summary>
        ///  保存sys_asset_a1信息
        /// </summary>
        /// <param name="ms">实体信息</param>
        /// <returns>消息</returns>
        public MsReturned Savesys_asset_a1(Mssys_asset_a1 ms)
        {
            return interface_sys_asset_a1.Savesys_asset_a1(ms);
        }

        /// <summary>
        /// 得到数据类型
        /// </summary>
        /// <param name="msquery">条件</param>
        /// <returns>数据类型</returns>
        public MsReturned Getsys_asset_a1ByQuery(MsQuery msquery)
        {
            if (msquery.typecode1==null ||msquery.typecode1 == "")
            {
                msquery.typecode1 = "sys";
            }
            Mssystem_1 mssys1 = (Mssystem_1)msquery.obj1;//当前用户
            //分类码资产需要加入角色条件
            if (!mssys1.isadmin && msquery.typecode1 == "asset")
            {
                try
                {
                    BLLsys_asset_a2 sysa2 = new BLLsys_asset_a2();
                    MsQuery msqsysa2 = new MsQuery();
                    msqsysa2.strquery = " and SYS_ASSET_A2_10='" + mssys1.sys10.System_10_10 + "'";//配置表
                    List<Mssys_asset_a2> listsysa2 = sysa2.Getsys_asset_a2MsByQuery(msqsysa2);
                    List<int> listid = listsysa2.ConvertAll(m => m.SYS_ASSET_A2_20);//得到ID
                    listid.Add(-1);
                    msquery.strquery += " and AUTOID in ('" + string.Join("','", listid) + "')";//增加查询条件
                }
                catch { }
            }
            else if (msquery.typecode1 == "sys")
            {

            }
            return interface_sys_asset_a1.Getsys_asset_a1ByQuery(msquery);
        }

        /// <summary>
        /// 删除sys_asset_a1
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public MsReturned Deletesys_asset_a1ByQuery(MsQuery msq)
        {
            return interface_sys_asset_a1.Deletesys_asset_a1ByQuery(msq);
        }
        /// <summary>
        /// 删除sys_asset_a1
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public MsReturned Deletesys_asset_a1ByKey(string AUTOID)
        {
            MsQuery msquery = new MsQuery();

            if (AUTOID.IndexOf(",") > 0)
            {
                msquery.strquery += " and AUTOID in (" + AUTOID + ") ";
            }
            else
            {
                msquery.strquery += " and AUTOID='" + AUTOID + "' ";
            }
            return interface_sys_asset_a1.Deletesys_asset_a1ByQuery(msquery);
        }


        /// <summary>
        /// 得到关联表的Table
        /// </summary>
        /// <param name="mssysA1">配置</param>
        /// <returns>DataTable</returns>
        public static DataTable GetIDJoinTable(Mssys_asset_a1 mssysA1)
        {
            string where = "";
            if (mssysA1.SYS_ASSET_A1_90 != "") {
                where = " and " + mssysA1.SYS_ASSET_A1_90.Replace("$tab$", mssysA1.SYS_ASSET_A1_60);
            }
            return new BLLsys_asset_a1().GetJoinTable(mssysA1.SYS_ASSET_A1_60, mssysA1.SYS_ASSET_A1_70, "", where);
        }

        /// <summary>
        /// 得到关联表的Table
        /// </summary>
        /// <param name="mssysA1">配置</param>
        /// <returns>DataTable</returns>
        public static DataTable GetJoinTable(Mssys_asset_a1 mssysA1)
        {
            string where = "";
            if (mssysA1.SYS_ASSET_A1_90 != "")
            {
                where = " and " + mssysA1.SYS_ASSET_A1_90.Replace("$tab$", mssysA1.SYS_ASSET_A1_60);
            }
            return new BLLsys_asset_a1().GetJoinTable(mssysA1.SYS_ASSET_A1_60, mssysA1.SYS_ASSET_A1_70, mssysA1.SYS_ASSET_A1_80, where);
        }

        /// <summary>
        /// 得到关联表的Table
        /// </summary>
        /// <param name="tablename">表名</param>
        /// <param name="idfield">id字段</param>
        /// <param name="strfield">显示字段</param>
        /// <returns>DataTable</returns>
        public static DataTable GetJoinTable(string tablename, string idfield, string strfield)
        {
            return new BLLsys_asset_a1().GetJoinTable(tablename, idfield, strfield,"");
        }

        /// <summary>
        /// 得到关联表的Table
        /// </summary>
        /// <param name="tablename">表名</param>
        /// <param name="idfield">id字段</param>
        /// <param name="strfield">显示字段</param>
        /// <param name="where">条件</param>
        /// <returns>DataTable</returns>
        public DataTable GetJoinTable(string tablename, string idfield, string strfield, string where)
        {
            return interface_sys_asset_a1.GetJoinTable( tablename,  idfield,  strfield,  where);
        }
    }
}
